package org.zty.service;
import java.util.List;
import org.zty.common.BaseService;
import org.zty.db.DBMgr;
import org.zty.domain.Attr;

import java.sql.SQLException;
import org.zty.util.ZException;
public class AttrService extends BaseService {
	public AttrService() {
		this.client = DBMgr.getSqlMapClient();
	}
	public void insertAttr(Attr attr) throws ZException{
		try {
			if(attr.getId()==0){
				attr.setId(this.getNextId("attr"));
			}
			this.client.insert("insertAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("新增Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("新增Attr失败",e);
		}
	}
	public void deleteAttr(Attr attr) throws ZException{
		try {
			this.client.delete("deleteAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("删除Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("删除Attr失败",e);
		}
	}
	public void updateAttr(Attr attr) throws ZException{
		try {
			this.client.update("updateAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("修改Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("修改Attr失败",e);
		}
	}
	public Attr getAttr(Attr attr) throws ZException{
		try {
			return (Attr)this.client.queryForObject("findAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取单Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取单Attr失败",e);
		}
	}
	public int findAttrTotal(Attr attr) throws ZException{
		try {
			return (int)this.client.queryForObject("findAttrTotal",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取总数Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取总数Attr失败",e);
		}
	}
	public List<Attr> findAllAttr(Attr attr) throws ZException{
		try {
			return this.client.queryForList("findAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取所有Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取所有Attr失败",e);
		}
	}
	public List<Attr> findAttrList(Attr attr) throws ZException{
		try {
			return this.client.queryForList("findAttr",attr,attr.getSkipSize(),attr.getPageSize());
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取Attr列表失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取Attr列表失败",e);
		}
	}
	public List<Attr> findAttrPaginationList(Attr attr) throws ZException{
		try {
			return this.client.queryForList("findPaginationListAttr",attr);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new ZException("获取物理分页Attr失败",e);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ZException("获取物理分页Attr失败",e);
		}
	}
}